<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@ include file="/include/service-base-header.jsp" %>
    <title>分销商管理</title>


</head>
<body>
<div class="wrapper">
    <jsp:include page="/include/left_menu.jsp">
        <jsp:param name="index" value="4"/>
    </jsp:include>
    <div class="main-panel">
        <nav class="navbar navbar-expand-lg navigation_shadow_none">
            <div class="container-fluid">
                <div class="navbar-wrapper b-navbar-wapper">
                    <a class="b-navbar-title" href="${pageContext.request.contextPath}/s/distribution.do">分销商管理</a>
                    <a class="b-navbar-title-active" href="#">佣金提现申请</a>
                </div>
            </div>
        </nav>

        <div class="container-fluid">
            <div class="row" style="margin-left: 3rem;margin-top: 1rem">
                <div style="width: 18rem;">
                    <div class="card card-stats" style="width: 16rem;height: 8rem;">
                        <div class="card-header card-header-successtwo card-header-icon">
                            <div class="card-icon" style="background: #F1A342 100%">
                                <img src="../image/one.svg" style="width: 3rem;height: 3rem;padding: 0.5rem">
                            </div>
                            <p class="card-category" style="margin-right: 0.5rem;">待提现佣金总额</p>
                            <h3 class="card-title" style="margin-right: 0.5rem;">
                                <span id="inMoneyAll"></span>
                                <small>KSH</small>
                            </h3>
                        </div>
                    </div>
                </div>
                <div style="width: 18rem;margin-left: 4rem">
                    <div class="card card-stats" style="width: 16rem;height: 8rem;">
                        <div class="card-header card-header-successtwo card-header-icon">
                            <div class="card-icon" style="background: #6DAC63 100%">
                                <img src="../image/two.svg" style="width: 3rem;height: 3rem;padding: 0.5rem">
                            </div>
                            <p class="card-category" style="margin-right: 0.5rem;">已提现佣金总额</p>
                            <h3 class="card-title" style="margin-right: 0.5rem;">
                                <span id="outMoney"></span>
                                <small>KSH</small>
                            </h3>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="card card-plain">
                        <div class="card-header card-header-primary">
                            <div class="card-title">提现列表</div>
                            <p class="card-category">审核代理商提现</p>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table" id="table">
                                    <thead class=" text-primary">
                                    <tr>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            #
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            发起提现时间
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            提现代理商
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            提现金额
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            提现到账户
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            操作
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <nav aria-label="page">
                        <ul class="pagination justify-content-center" id="p1">
                        </ul>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>

</body>

<script>
    var data_source;
    var page_count = 15;
    findSalesList();
    function findSalesList() {
        var data = {};
        $.ajax({
            url: baseUrl.base + baseUrl.sales + "/salesGetMoneyList",
            type: 'get',
            data: data,
            success: function (data) {
                if (data.code == "0") {
                    var res = data.results;
                    data_source = res.getMoneyLists;
                    cutPagination(1);
                    $("#inMoneyAll").html(res.inMoneyAll);
                    $("#outMoney").html(res.outMoney);
                    // 配置分页
                    $("#p1").pagination({
                        totalData: res.length,
                        showData: page_count,
                        callback: function (idx) {
                            cutPagination(idx);
                        }
                    });
                } else {
                    var res = data.msg;
                    alert(res);
                }
            }
        });
    };

    /**
     * 分页
     * @param page 从1开始
     */
    function cutPagination(page) {

        var start = (page - 1) * page_count;
        var end = start + page_count;

        if (end > data_source.length) {
            end = data_source.length;
        }

        $("#tbody").empty();

        for (var i = start; i < end; i++) {
            var sales = data_source[i];

            var tr = document.createElement("tr");
            var td = document.createElement("td");
            var tdContent = document.createTextNode(i + 1);
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(timestampToTime(sales.createTime));
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            var name = document.createTextNode(sales.salesName);
            td.appendChild(name);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(sales.cashMoney + "KSH");
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(sales.cashAccount);
            td.appendChild(tdContent);
            tr.appendChild(td);


            var td = document.createElement("td");
            var btn1 = document.createElement("button");
            btn1.setAttribute("type", "button");
            btn1.setAttribute("class", "btn btn-info btn-sm");
            btn1.setAttribute("cashId", sales.forWardId);

            btn1.onclick = function (ev) {
                cashfalse(this);
            }
            var tdContent = document.createTextNode("不通过");
            btn1.appendChild(tdContent);
            td.appendChild(btn1);

            var btn2 = document.createElement("button");
            btn2.setAttribute("type", "button");

            var btn2 = document.createElement("button");
            btn2.setAttribute("type", "button");
            btn2.setAttribute("class", "btn btn-success btn-sm");
            btn2.setAttribute("cashId", sales.forWardId);
            btn2.onclick = function (ev) {
                cashTrue(this);
            }
            var tdContent = document.createTextNode(" 通  过 ");
            btn2.appendChild(tdContent);
            td.appendChild(btn2);
            tr.appendChild(td);

            document.getElementById("tbody").append(tr);
            document.getElementById("tbody").innerHTML;
        }
    }

    function cashfalse(colom) {
        var datas = {};
        datas.putForwardId = colom.getAttribute("cashId");
        datas.cashState = 3;
        $.ajax({
            url: baseUrl.base + baseUrl.sales + '/updateCheck',
            type: 'get',
            data: datas,
            success: function (data) {
                if (data.code == "0") {
                    showNotification('bottom', 'right', '提现驳回成功');
                    findSalesList();
                }
            }
        })
    };

    function cashTrue(colom) {
        var datas = {};
        datas.putForwardId = colom.getAttribute("cashId");
        datas.cashState = 2;
        $.ajax({
            url: baseUrl.base + baseUrl.sales + '/updateCheck',
            type: 'get',
            data: datas,
            success: function (data) {
                if (data.code == "0") {
                    showNotification('bottom', 'right', '提现确认成功');
                    findSalesList();
                }
            }
        })
    };
</script>
</html>